using DAO;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Easislides
{
	public class FrmRecoverDeleted : Form
	{
		private int sortColumn = -1;
		private bool InitListItems = true;
		private IContainer components = null;
		private Button BtnCancel;
		private Button BtnOK;
		private ListView SongsList;
		private ColumnHeader columnHeader1;
		private ColumnHeader columnHeader2;
		private ColumnHeader columnHeader3;
		private CheckBox cbTickAll;
		private ColumnHeader columnHeader4;
		private ToolTip toolTip1;
		private Label label1;
		private ColumnHeader columnHeader5;
		public FrmRecoverDeleted()
		{
			this.InitializeComponent();
		}
		private void FrmRecoverDeleted_Load(object sender, EventArgs e)
		{
			try
			{
				this.InitListItems = true;
				ListViewItem listViewItem = new ListViewItem();
				string fullSearchString = "select * from SONG where FolderNo=" + 0.ToString() + " order by LastModified";
				Recordset recordSet = gf.GetRecordSet(gf.ConnectStringMainDB, fullSearchString);
				this.SongsList.Sorting = SortOrder.None;
				if (recordSet != null && !recordSet.EOF)
				{
					recordSet.MoveFirst();
					while (!recordSet.EOF)
					{
						int num = gf.ObjToInt(recordSet.Fields["OldFolder"].Value);
						if (num < 0 | num > 41)
						{
							num = 1;
						}
						DateTime dateTime = gf.ObjToDate(recordSet.Fields["LastModified"].Value);
						listViewItem = this.SongsList.Items.Add(gf.ObjToString(recordSet.Fields["Title_1"].Value));
						listViewItem.SubItems.Add(gf.FolderName[num]);
						listViewItem.SubItems.Add(dateTime.ToString("yyyy-MM-dd"));
						listViewItem.SubItems.Add(gf.ObjToString(recordSet.Fields["SongID"].Value));
						listViewItem.SubItems.Add(num.ToString());
						recordSet.MoveNext();
					}
				}
				this.SongsList.Sorting = SortOrder.Ascending;
				this.SongsList.Sort();
				this.SongsList.Sorting = SortOrder.None;
			}
			catch
			{
			}
			this.InitListItems = false;
			this.SetButtons();
		}
		private void BtnOK_Click(object sender, EventArgs e)
		{
			if (this.SongsList.CheckedItems.Count > 0)
			{
				this.Cursor = Cursors.WaitCursor;
				if (MessageBox.Show("Recover the Ticked song(s) to their Original Folders?", "Recover Song(s)", MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					if (gf.ReFileSelectedSongs(ref this.SongsList) == 0)
					{
						this.Cursor = Cursors.Default;
						base.DialogResult = DialogResult.OK;
						base.Close();
					}
					else
					{
						MessageBox.Show("Not all the ticked songs were recovered, please try again");
						this.SetButtons();
					}
				}
				else
				{
					this.SetButtons();
				}
				this.Cursor = Cursors.Default;
			}
		}
		private void SetButtons()
		{
			if (this.SongsList.Items.Count != 0)
			{
				this.InitListItems = true;
				if (this.cbTickAll.CheckState == CheckState.Checked)
				{
					for (int i = this.SongsList.Items.Count - 1; i >= 0; i--)
					{
						this.SongsList.Items[i].Checked = true;
					}
				}
				else
				{
					if (this.cbTickAll.CheckState == CheckState.Unchecked)
					{
						for (int i = this.SongsList.Items.Count - 1; i >= 0; i--)
						{
							this.SongsList.Items[i].Checked = false;
						}
					}
				}
				this.SongsList.Columns[0].Text = this.SongsList.Items.Count.ToString() + " items listed / " + this.SongsList.CheckedItems.Count.ToString() + " ticked for recovery.";
				this.BtnOK.Enabled = (this.SongsList.CheckedItems.Count > 0);
				this.InitListItems = false;
			}
		}
		private void SongsList_ItemChecked(object sender, ItemCheckedEventArgs e)
		{
			if (!this.InitListItems)
			{
				this.SongsListItemTicked();
			}
		}
		private void SongsListItemTicked()
		{
			if (this.SongsList.Items.Count == this.SongsList.CheckedItems.Count)
			{
				this.cbTickAll.CheckState = CheckState.Checked;
			}
			else
			{
				if (this.SongsList.CheckedItems.Count == 0)
				{
					this.cbTickAll.CheckState = CheckState.Unchecked;
				}
				else
				{
					this.cbTickAll.CheckState = CheckState.Indeterminate;
				}
			}
			this.SetButtons();
		}
		private void cbTickAll_CheckedChanged(object sender, EventArgs e)
		{
			this.SetButtons();
		}
		private void SongsList_ColumnClick(object sender, ColumnClickEventArgs e)
		{
			lv.Sort(ref this.SongsList, ref this.sortColumn, e.Column, true);
		}
		private void oldSongsList_ColumnClick(object sender, ColumnClickEventArgs e)
		{
			if (e.Column != this.sortColumn)
			{
				this.sortColumn = e.Column;
				this.SongsList.Sorting = SortOrder.Ascending;
			}
			else
			{
				if (this.SongsList.Sorting == SortOrder.Ascending)
				{
					this.SongsList.Sorting = SortOrder.Descending;
				}
				else
				{
					this.SongsList.Sorting = SortOrder.Ascending;
				}
			}
			this.SongsList.Sort();
			this.SongsList.ListViewItemSorter = new ListViewItemComparer(e.Column, this.SongsList.Sorting);
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            this.BtnCancel = new System.Windows.Forms.Button();
            this.BtnOK = new System.Windows.Forms.Button();
            this.SongsList = new System.Windows.Forms.ListView();
            this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.cbTickAll = new System.Windows.Forms.CheckBox();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // BtnCancel
            // 
            this.BtnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.BtnCancel.Location = new System.Drawing.Point(379, 255);
            this.BtnCancel.Name = "BtnCancel";
            this.BtnCancel.Size = new System.Drawing.Size(80, 24);
            this.BtnCancel.TabIndex = 3;
            this.BtnCancel.Text = "Close";
            this.BtnCancel.Click += new System.EventHandler(this.BtnCancel_Click);
            // 
            // BtnOK
            // 
            this.BtnOK.Location = new System.Drawing.Point(284, 255);
            this.BtnOK.Name = "BtnOK";
            this.BtnOK.Size = new System.Drawing.Size(80, 24);
            this.BtnOK.TabIndex = 2;
            this.BtnOK.Text = "Recover";
            this.BtnOK.Click += new System.EventHandler(this.BtnOK_Click);
            // 
            // SongsList
            // 
            this.SongsList.CheckBoxes = true;
            this.SongsList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader1,
            this.columnHeader2,
            this.columnHeader3,
            this.columnHeader4,
            this.columnHeader5});
            this.SongsList.FullRowSelect = true;
            this.SongsList.Location = new System.Drawing.Point(12, 26);
            this.SongsList.Name = "SongsList";
            this.SongsList.ShowItemToolTips = true;
            this.SongsList.Size = new System.Drawing.Size(447, 224);
            this.SongsList.Sorting = System.Windows.Forms.SortOrder.Ascending;
            this.SongsList.TabIndex = 0;
            this.SongsList.UseCompatibleStateImageBehavior = false;
            this.SongsList.View = System.Windows.Forms.View.Details;
            this.SongsList.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.SongsList_ColumnClick);
            this.SongsList.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.SongsList_ItemChecked);
            // 
            // columnHeader1
            // 
            this.columnHeader1.Text = "";
            this.columnHeader1.Width = 239;
            // 
            // columnHeader2
            // 
            this.columnHeader2.Text = "Restore to Folder";
            this.columnHeader2.Width = 106;
            // 
            // columnHeader3
            // 
            this.columnHeader3.Text = "Deleted (Y-M-D)";
            this.columnHeader3.Width = 97;
            // 
            // columnHeader4
            // 
            this.columnHeader4.Text = "Song ID";
            this.columnHeader4.Width = 0;
            // 
            // columnHeader5
            // 
            this.columnHeader5.Text = "FolderNo";
            this.columnHeader5.Width = 0;
            // 
            // cbTickAll
            // 
            this.cbTickAll.AutoSize = true;
            this.cbTickAll.Location = new System.Drawing.Point(21, 255);
            this.cbTickAll.Name = "cbTickAll";
            this.cbTickAll.Size = new System.Drawing.Size(61, 17);
            this.cbTickAll.TabIndex = 1;
            this.cbTickAll.Text = "Tick All";
            this.cbTickAll.ThreeState = true;
            this.cbTickAll.CheckedChanged += new System.EventHandler(this.cbTickAll_CheckedChanged);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(19, 8);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(285, 13);
            this.label1.TabIndex = 4;
            this.label1.Text = "Tick the items you wish to restore and then click \'Recover\':";
            // 
            // FrmRecoverDeleted
            // 
            this.AcceptButton = this.BtnOK;
            this.CancelButton = this.BtnCancel;
            this.ClientSize = new System.Drawing.Size(471, 292);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.cbTickAll);
            this.Controls.Add(this.SongsList);
            this.Controls.Add(this.BtnCancel);
            this.Controls.Add(this.BtnOK);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FrmRecoverDeleted";
            this.ShowIcon = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Recover Deleted Songs";
            this.Load += new System.EventHandler(this.FrmRecoverDeleted_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

		}

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }
	}
}
